package cn.breeze.order.controller;

import cn.breeze.order.dto.ConfirmOrderDto;
import cn.breeze.order.service.IOrderPetAcquisitionService;
import cn.breeze.order.domain.OrderPetAcquisition;
import cn.breeze.order.query.OrderPetAcquisitionQuery;
import cn.breeze.basic.utils.AjaxResult;
import cn.breeze.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.breeze.basic.exception.BusinessException;
import cn.breeze.basic.annotation.PreAuthorize;

import java.util.List;

@RestController
@RequestMapping("/orderPetAcquisition")
public class OrderPetAcquisitionController {
    @Autowired
    private  IOrderPetAcquisitionService orderPetAcquisitionService;


    /**
     * 保存和修改公用的
     * @param orderPetAcquisition  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    @PreAuthorize(name = "保存orderPetAcquisition", sn = "orderPetAcquisition:save")
    public AjaxResult addOrUpdate(@RequestBody OrderPetAcquisition orderPetAcquisition){
        try {
            if( orderPetAcquisition.getId()!=null)
                orderPetAcquisitionService.update(orderPetAcquisition);
            else
                orderPetAcquisitionService.save(orderPetAcquisition);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }
    /**
    * 取消订单
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
   /* @PreAuthorize(name = "取消订单", sn = "orderPetAcquisition:delete")*/
    public AjaxResult cancelOrder(@PathVariable("id") Long id){
        try {
            orderPetAcquisitionService.cancelOrder(id);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试1");
        }
    }

    /**
    * @Title: confirm
    * @Description: 确认订单
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/7/20 18:16
    * @Parameters: [id]
    * @Return cn.breeze.basic.utils.AjaxResult
    */
    @PostMapping(value="/confirm")
    /*@PreAuthorize(name = "确认订单", sn = "orderPetAcquisition:confirm")*/
    public AjaxResult confirm(@RequestBody ConfirmOrderDto confirmOrderDto){
        try {
            orderPetAcquisitionService.confirm(confirmOrderDto);
            return AjaxResult.me();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试1");
        }
    }
	
    //获取用户
    @GetMapping("/{id}")
    @PreAuthorize(name = "获取orderPetAcquisition", sn = "orderPetAcquisition:get")
    public OrderPetAcquisition get(@PathVariable("id")Long id)
    {
        return orderPetAcquisitionService.loadById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    @PreAuthorize(name = "获取所有orderPetAcquisition", sn = "orderPetAcquisition:loadAll")
    public List<OrderPetAcquisition> list(){

        return orderPetAcquisitionService.loadAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping
    @PreAuthorize(name = "列表orderPetAcquisition", sn = "orderPetAcquisition:list")
    public PageList<OrderPetAcquisition> queryData(@RequestBody OrderPetAcquisitionQuery query)
    {
        return orderPetAcquisitionService.queryData(query);
    }

    /**
    * @Title: patchRemove
    * @Description: 批量删除
    * @Author: Mr.D
    * @Version: 1.0
    * @Date:  2022/7/18 16:57
    * @Parameters: [ids]
    * @Return cn.breeze.basic.utils.AjaxResult
    */
    @PatchMapping
    @PreAuthorize(name = "批量删除orderPetAcquisition", sn = "orderPetAcquisition:patchDelete")
    public AjaxResult patchRemove(@RequestBody Long[] ids){
        try {
            orderPetAcquisitionService.patchRemove(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请稍后再试试！");
        }
    }
}
